
<template>
  <div class="page" id="applylList">
      <div class="list-hd">
          <div class="pickers">
            <select-type objectName="wh_hotel" fieldName="checkin_area"/>
            <index-bar-hospital />
          </div>
          <van-field v-model="searchTxt" placeholder="地址关键词">
              <van-button slot="button" type="primary" round size="small" @click="getLists">查询</van-button>
          </van-field>
       </div>

          <div class="item" v-for="(i,index) in items" :key="index">
              <div class="item-hd">
                  <span>{{i.date_begin}}</span>
                  <span class="item__value" style="color:#07c160">
                      {{i.Dicts ? i.Dicts.name : ''}}
                  </span>
              </div>
              <div class="item-bd">
                  {{i.showAddr}}
              </div>
              <div class="item-ft">
                  <van-button v-if="i.state==2" type="default" size="small" round plain url="#">已拒绝</van-button>
                  <van-button v-if="i.state==1" type="primary" size="small" round url="/apply_detail">我来接单</van-button>
                  <van-button v-if="i.state==5" type="primary" size="small" round plain url="'/apply_detail">查看详情</van-button>
              </div>
          </div>
          <div class="item-empty" v-show="isEmpty">
              <p><van-icon name="bulb-o" size="60"/></p>
              <p>没有查询出符合条件的申请信息, 换个条件试试~</p>
          </div>
      <div class="ft-cover">
          <van-button type="primary" block round url="/admin/hotel/create">发布酒店信息</van-button>
      </div>
  </div>
</template>

<script>
  import apply from "@/modules/freestay/api/apply";
  import SelectType from "../components/SelectType";
  import IndexBarHospital from "../components/IndexBarHospital";
  import { Toast,Dialog } from 'vant';

  export default {
    components: {
      SelectType,
      IndexBarHospital
    },
    data() {
      return {
        checkeds: [],
        searchTxt: '',
        areaValue: 0,
        showMyApply: false,
        items: [],
        hospitalValue: 0,
        isEmpty: false,
      }
    },
    mounted() {
      this.areaValue = this.$store.state.areaValue;
      console.log('applys - areaValue='+this.areaValue);
      this.getLists();
    },
    methods: {
      selectedArea(value) {
        this.areaValue = value;
      },
      selectedHospital(value) {
        this.hospitalValue = value.id;
      },
      myApply() {
        this.showMyApply = true;
      },
      orderIt(item) {
        let msg = '请确定是否具备接待能力：\n'+
                  '\n入住人数：'+item.checkin_num+
                  '\n入住开始日期：'+item.date_begin+
                  '\n入住结束日期：'+item.date_end;
        Dialog.confirm({
          title: '我来接单',
          message: msg
        }).then(() => {
          Toast('抱歉，在等等...')
        }).catch(() => {
          // on cancel
        });
      },
      // 调用api获得当前选择的申请列表
      getLists(){
        console.log(this.$store.state.common.areaValue+'--'+this.$store.state.common.hospitalValue);
        apply.getApplys(
          this.$store.state.common.areaValue,
          this.$store.state.common.hospitalValue,
          this.searchAddr,
          data => {
            data = data['[]'];
            this.items = [];
            if(data!=undefined&&data.length>0) {
              this.isEmpty = false;
              for(var i in data) {
                var a = data[i].Wh_subscribe;
                var h = data[i].Wh_hotel;
                var hs = data[i].Wh_hospital;
                var d = data[i].Dicts;
                a['Wh_hotel'] = h==undefined?{}:h;
                a['Dicts'] = d==undefined?{}:d;
                a['Wh_hospital'] = hs==undefined?{}:hs;
                if(hs)
                  a['showAddr'] = hs.hospital_name+'-'+a.hope_addr;
                else if(h)
                  a['showAddr'] = h.hotel_name+h.address+'附近'
                else
                  a['showAddr'] = ''
                a['showAddr'] += a.conn_person+a.checkin_num+'名 '+a.conn_phone+'急需酒店。联系人：'+a.conn_person
                this.items.push(a);
              }    
            }
            else{4
              this.isEmpty = true;              
            }
          },
          err => {
              Toast('读取申请记录失败:'+err); 
          });
      },
    }
  }
</script>
<style scoped src="../assets/css/app.css"/>
<style scoped>
p{
  padding-left:10px;
}
</style>
  